<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="订单ID" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单号" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="vin码" prop="vehicleVin">
        <el-input
          v-model="queryParams.vehicleVin"
          placeholder="请输入vin码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="集装箱号" prop="containerCode">
        <el-input
          v-model="queryParams.containerCode"
          placeholder="请输入集装箱号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="节点事件" prop="nodeEvent">
        <el-input
          v-model="queryParams.nodeEvent"
          placeholder="请输入节点事件"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品牌" prop="brandName">
        <el-input
          v-model="queryParams.brandName"
          placeholder="请输入品牌"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车系" prop="series">
        <el-input
          v-model="queryParams.series"
          placeholder="请输入车系"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="颜色名称" prop="colorName">
        <el-input
          v-model="queryParams.colorName"
          placeholder="请输入颜色名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车型名称" prop="modelName">
        <el-input
          v-model="queryParams.modelName"
          placeholder="请输入车型名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="到库日期" prop="arrivalDate">
        <el-date-picker clearable
          v-model="queryParams.arrivalDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择到库日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="操作人" prop="operator">
        <el-input
          v-model="queryParams.operator"
          placeholder="请输入操作人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['system:vehicle:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:vehicle:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:vehicle:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:vehicle:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="vehicleList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="车辆ID" align="center" prop="orderVehicleId" />
      <el-table-column label="订单ID" align="center" prop="orderId" />
      <el-table-column label="订单号" align="center" prop="orderCode" />
     <el-table-column label="vin码" align="center" prop="vehicleVin" />
      <el-table-column label="集装箱号" align="center" prop="containerCode" />
      <el-table-column label="入场状态" align="center" prop="inStatus" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_order_vehicle_in_out_status" :value="scope.row.inStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="装箱状态" align="center" prop="outStatus" >
                <template slot-scope="scope">
                  <dict-tag :options="dict.type.sys_order_vehicle_in_out_status" :value="scope.row.outStatus"/>
                </template>
      </el-table-column>
      <el-table-column label="节点事件" align="center" prop="nodeEvent" />
      <el-table-column label="数量" align="center" prop="vehicleNum" />
      <el-table-column label="品牌" align="center" prop="brandName" />
      <el-table-column label="车系" align="center" prop="series" />
      <el-table-column label="颜色名称" align="center" prop="colorName" />
      <el-table-column label="车型名称" align="center" prop="modelName" />
      <el-table-column label="交车单位" align="center" prop="deliveryUnit" />
      <el-table-column label="交车人员" align="center" prop="deliveryPersonnel" />
      <el-table-column label="责任单位" align="center" prop="responsibleUnit" />
      <el-table-column label="运输工具号" align="center" prop="transportNumber" />
      <el-table-column label="质量交接编号" align="center" prop="qualityHandoverNumber" />
      <el-table-column label="装载位置" align="center" prop="loadingLocation" />
      <el-table-column label="责任分区" align="center" prop="responsibilityPartition" />
      <el-table-column label="分区" align="center" prop="subarea" />
      <el-table-column label="接车单位" align="center" prop="receivingUnit" />
      <el-table-column label="接车人员" align="center" prop="receivingPersonnel" />
      <el-table-column label="发现环节" align="center" prop="discoveryProcess" />
      <el-table-column label="到库日期" align="center" prop="arrivalDate" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.arrivalDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="装车日期" align="center" prop="loadingDate" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.loadingDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="运输方式" align="center" prop="transportType" />
      <el-table-column label="操作人" align="center" prop="operator" />
      <el-table-column label="操作时间" align="center" prop="operationTime" width="110">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.operationTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作仓库" align="center" prop="operationWarehouse" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="120px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:vehicle:edit']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:vehicle:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单-车辆信息对话框 -->
    <el-dialog :title="title" :visible.sync="open"  append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="110px"  :disabled="isDisabled">
        <el-row>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="订单ID" prop="orderId">
                <el-input v-model="form.orderId" placeholder="请输入订单ID" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="订单号" prop="orderCode">
                <el-input v-model="form.orderCode" placeholder="请输入订单号" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="订单集装箱ID" prop="orderContainerId">
                <el-input v-model="form.orderContainerId" placeholder="请输入订单集装箱ID" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="vin码" prop="vehicleVin">
                <el-input v-model="form.vehicleVin" placeholder="请输入vin码" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="集装箱号" prop="containerCode">
                <el-input v-model="form.containerCode" placeholder="请输入集装箱号" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="节点事件" prop="nodeEvent">
                <el-input v-model="form.nodeEvent" placeholder="请输入节点事件" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="数量" prop="vehicleNum">
                <el-input v-model="form.vehicleNum" placeholder="请输入数量" />
              </el-form-item>
            </el-col>
            <el-col :span="8">

              <el-form-item label="品牌" prop="brandName">
                <el-input v-model="form.brandName" placeholder="请输入品牌" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="车系" prop="series">
                <el-input v-model="form.series" placeholder="请输入车系" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="颜色名称" prop="colorName">
                <el-input v-model="form.colorName" placeholder="请输入颜色名称" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="车型名称" prop="modelName">
                <el-input v-model="form.modelName" placeholder="请输入车型名称" />
              </el-form-item>
            </el-col>
            <el-col :span="8">

              <el-form-item label="交车单位" prop="deliveryUnit">
                <el-input v-model="form.deliveryUnit" placeholder="请输入交车单位" />
              </el-form-item>
            </el-col>
          </el-col>

          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="交车人员" prop="deliveryPersonnel">
                <el-input v-model="form.deliveryPersonnel" placeholder="请输入交车人员" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="责任单位" prop="responsibleUnit">
                <el-input v-model="form.responsibleUnit" placeholder="请输入责任单位" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="运输工具号" prop="transportNumber">
                <el-input v-model="form.transportNumber" placeholder="请输入运输工具号" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="质量交接编号" prop="qualityHandoverNumber">
                <el-input v-model="form.qualityHandoverNumber" placeholder="请输入质量交接编号" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="装载位置" prop="loadingLocation">
                <el-input v-model="form.loadingLocation" placeholder="请输入装载位置" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="责任分区" prop="responsibilityPartition">
                <el-input v-model="form.responsibilityPartition" placeholder="请输入责任分区" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="分区" prop="subarea">
                <el-input v-model="form.subarea" placeholder="请输入分区" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="接车单位" prop="receivingUnit">
                <el-input v-model="form.receivingUnit" placeholder="请输入接车单位" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="接车人员" prop="receivingPersonnel">
                <el-input v-model="form.receivingPersonnel" placeholder="请输入接车人员" />
              </el-form-item>
            </el-col>
          </el-col>
          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="发现环节" prop="discoveryProcess">
                <el-input v-model="form.discoveryProcess" placeholder="请输入发现环节" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="到库日期" prop="arrivalDate">
                <el-date-picker clearable
                                v-model="form.arrivalDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择到库日期"
                                style="width: 140px">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="操作人" prop="operator">
                <el-input v-model="form.operator" placeholder="请输入操作人" />
              </el-form-item>
            </el-col>
          </el-col>

          <el-col :span="24">
            <el-col :span="8">
              <el-form-item label="操作时间" prop="operationTime">
                <el-date-picker clearable
                                v-model="form.operationTime"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择操作时间"
                                style="width: 140px">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="操作仓库" prop="operationWarehouse">
                <el-input v-model="form.operationWarehouse" placeholder="请输入操作仓库" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="备注" prop="remark">
                <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
              </el-form-item>
            </el-col>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listVehicle, getVehicle, delVehicle, addVehicle, updateVehicle } from "@/api/system/order/vehicle";

export default {
  name: "Vehicle",
  dicts: [ 'sys_order_vehicle_status','sys_order_vehicle_in_out_status'],
  data() {
    return {
      isDisabled:true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单-车辆信息表格数据
      vehicleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderId: null,
        orderCode: null,
        orderContainerId: null,
        vehicleVin: null,
        containerCode: null,
        status: null,
        nodeEvent: null,
        vehicleNum: null,
        brandName: null,
        series: null,
        colorName: null,
        modelName: null,
        deliveryUnit: null,
        deliveryPersonnel: null,
        responsibleUnit: null,
        transportNumber: null,
        qualityHandoverNumber: null,
        loadingLocation: null,
        responsibilityPartition: null,
        subarea: null,
        receivingUnit: null,
        receivingPersonnel: null,
        discoveryProcess: null,
        arrivalDate: null,
        transportType: null,
        operator: null,
        operationTime: null,
        operationWarehouse: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderId: [
          { required: true, message: "订单ID不能为空", trigger: "blur" }
        ],
        orderCode: [
          { required: true, message: "订单号不能为空", trigger: "blur" }
        ],
        orderContainerId: [
          { required: true, message: "订单集装箱ID不能为空", trigger: "blur" }
        ],
        vehicleVin: [
          { required: true, message: "vin码不能为空", trigger: "blur" }
        ],
        containerCode: [
          { required: true, message: "集装箱号不能为空", trigger: "blur" }
        ],
        // status: [
        //   { required: true, message: "状态不能为空", trigger: "change" }
        // ],
        // nodeEvent: [
        //   { required: true, message: "节点事件不能为空", trigger: "blur" }
        // ],
        // vehicleNum: [
        //   { required: true, message: "数量不能为空", trigger: "blur" }
        // ],
        brandName: [
          { required: true, message: "品牌不能为空", trigger: "blur" }
        ],
        series: [
          { required: true, message: "车系不能为空", trigger: "blur" }
        ],
        colorName: [
          { required: true, message: "颜色名称不能为空", trigger: "blur" }
        ],
        // modelName: [
        //   { required: true, message: "车型名称不能为空", trigger: "blur" }
        // ],
        // deliveryUnit: [
        //   { required: true, message: "交车单位不能为空", trigger: "blur" }
        // ],
        // deliveryPersonnel: [
        //   { required: true, message: "交车人员不能为空", trigger: "blur" }
        // ],
        // responsibleUnit: [
        //   { required: true, message: "责任单位不能为空", trigger: "blur" }
        // ],
        // transportNumber: [
        //   { required: true, message: "运输工具号不能为空", trigger: "blur" }
        // ],
        // qualityHandoverNumber: [
        //   { required: true, message: "质量交接编号不能为空", trigger: "blur" }
        // ],
        // loadingLocation: [
        //   { required: true, message: "装载位置不能为空", trigger: "blur" }
        // ],
        // responsibilityPartition: [
        //   { required: true, message: "责任分区不能为空", trigger: "blur" }
        // ],
        // subarea: [
        //   { required: true, message: "分区不能为空", trigger: "blur" }
        // ],
        // receivingUnit: [
        //   { required: true, message: "接车单位不能为空", trigger: "blur" }
        // ],
        // receivingPersonnel: [
        //   { required: true, message: "接车人员不能为空", trigger: "blur" }
        // ],
        // discoveryProcess: [
        //   { required: true, message: "发现环节不能为空", trigger: "blur" }
        // ],
        // transportType: [
        //   { required: true, message: "运输方式不能为空", trigger: "change" }
        // ],
        // operator: [
        //   { required: true, message: "操作人不能为空", trigger: "blur" }
        // ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单-车辆信息列表 */
    getList() {
      this.loading = true;
      listVehicle(this.queryParams).then(response => {
        this.vehicleList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderVehicleId: null,
        orderId: null,
        orderCode: null,
        orderContainerId: null,
        vehicleVin: null,
        containerCode: null,
        status: null,
        nodeEvent: null,
        vehicleNum: null,
        brandName: null,
        series: null,
        colorName: null,
        modelName: null,
        deliveryUnit: null,
        deliveryPersonnel: null,
        responsibleUnit: null,
        transportNumber: null,
        qualityHandoverNumber: null,
        loadingLocation: null,
        responsibilityPartition: null,
        subarea: null,
        receivingUnit: null,
        receivingPersonnel: null,
        discoveryProcess: null,
        arrivalDate: null,
        transportType: null,
        operator: null,
        operationTime: null,
        operationWarehouse: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderVehicleId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加订单-车辆信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderVehicleId = row.orderVehicleId || this.ids
      getVehicle(orderVehicleId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单-车辆信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderVehicleId != null) {
            updateVehicle(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addVehicle(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderVehicleIds = row.orderVehicleId || this.ids;
      this.$modal.confirm('是否确认删除订单-车辆信息编号为"' + orderVehicleIds + '"的数据项？').then(function() {
        return delVehicle(orderVehicleIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/vehicle/export', {
        ...this.queryParams
      }, `vehicle_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
